package com.map.module.lib;

import java.util.List;
import com.baidu.mapapi.search.core.PoiInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 地图搜索 适配器
 * @author wangqingcai
 *
 */
public class PoiSearchAdapter  extends BaseAdapter{

    private Context context;
    private List<PoiInfo> list;
    private ViewHolder holder;

    public PoiSearchAdapter(Context context) {
        this.context = context; 
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    public void update(List<PoiInfo> list) {
    	this.list = list;
		notifyDataSetChanged();
	}
    @Override
    public Object getItem(int location) {
        return list.get(location);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    public void addObject(List<PoiInfo> mAppGroup) {
        this.list = mAppGroup;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_poi_search_item, null);
            holder.mpoi_name = (TextView) convertView.findViewById(R.id.mpoiNameT);
            holder.mpoi_address = (TextView) convertView.findViewById(R.id.mpoiAddressT);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mpoi_name.setText(list.get(position).name);
        holder.mpoi_address.setText(list.get(position).address);
        return convertView;
    }

    public class ViewHolder {
        public TextView mpoi_name;// 名称
        public TextView mpoi_address;// 地址

    }

}
